<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>基础字典详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <script type="text/javascript" src="${basePath}/js/ecommerce.js"></script>
    <style type="text/css">
        .table1 {
            width: auto;
        }

        tbody {
            border: solid #ccc 1px;
            width: 100%;
        }

        .table1 tr {
            border: solid #ccc 1px;
            width: 100%;
        }

        .table1 tr th {
            min-width: 80px;
            width: auto;
        }

        .table1 tr td input {
            width: 100%;
        }

    </style>
</head>
<body>

<div class="content content_frame">
    <h3 class="mainTitle"><img src="${basePath}/images/icon2.png"/>基础字典详情->${tDictManager.tableDesc}</h3>
    </br>
    <ul class="contentNav dib-wrap">
        <input type="hidden" name="tableName"
               value="${tDictManager.tableName}">

        <li class="dib" id="btnSearch" defaultkey='13'>
            <a><i class='fa fa-search'></i>&nbsp;&nbsp;查&nbsp;询 </a>
        </li>
        <li class="dib" id="btnAdd">
            <a>
                <i class='fa fa-plus'></i>&nbsp;&nbsp;新&nbsp;增</a>
        </li>
        <li class="dib" id="btnModify">
            <a><i class='fa fa-edit'></i>&nbsp;&nbsp;修&nbsp;改 </a>
        </li>
        <li class="dib " id="btnDelete">
            <a>
                <i class='fa fa-trash-o'></i>&nbsp;&nbsp;删&nbsp;除 </a>
        </li>
        <li class="dib ">
            <a onclick="ClearAllInput('SearchTable')">
                <i class='fa fa-refresh'></i>&nbsp;&nbsp;重&nbsp;置 </a>
        </li>
        <li class="dib ">
            <a onclick="javascript:history.go(-1)">
                <i class='fa fa-reply'></i>&nbsp;&nbsp;返&nbsp;回 </a>
        </li>
    </ul>
    <br/>

    <form id="SearchTable">
        <table class="table1" style="display: block">
            <tbody>
            <tr>
                <th>编码</th>
                <td width="300">
                    <input type="text" placeholder="编码" datafield="SearchTable.code">
                </td>
                <th>中文名称</th>
                <td width="300">
                    <input type="text" placeholder="中文名称" datafield="SearchTable.cnName">
                </td>
                <c:if test="${! empty tDictManager.enNameKey}">
                    <th>英文名称</th>
                    <td width="300">
                        <input type="text" placeholder="英文名称" datafield="SearchTable.enName">
                    </td>
                </c:if>
            </tr>
            </tbody>
        </table>
    </form>
    <div class="cl"></div>
    <br/>
    <table id="baseDict" style="height: 1px">
    </table>
    <div id="baseDictPage">
    </div>
</div>
<script type="text/javascript">
    $(function () {
        function urlCode(cellvalue, options, rowObject) {
            cellvalue = cellvalue || '';
            cellvalue = $.trim(cellvalue);
            var url = '${basePath}/baseDict/getDictContentDetail?modify=false&tableName=${tDictManager.tableName}&indx=' + rowObject.indx;
            return "<a class='btn-link' href=\"" + url + "\">" + "<span style='color:#00acec'>" + cellvalue + "</span></a>";
        }

        function reloadGrid() {
            var jsonStr = customFormToData("SearchTable");
            $("#baseDict").jqGrid('setGridParam', {
                url: $basePath + "/baseDict/qryDictContentPage?enable=1&tableName=${tDictManager.tableName}",
                postData: JSON.parse(jsonStr), //发送数据
                mtype: 'POST',
                page: 1
            }).trigger("reloadGrid"); //重新载入
        }

        $("#baseDict").jqGrid({
            datatype: "json",
            url: $basePath + "/baseDict/qryDictContentPage?enable=1&tableName=${tDictManager.tableName}",
            colNames: [
                '序号',
                <c:if test="${! empty tDictManager.codeKey}">
                <c:choose>
                <c:when test="${! empty tDictManager.codeName}">
                ${tDictManager.codeName},
                </c:when>
                <c:otherwise>
                '字典编码',
                </c:otherwise>
                </c:choose>
                </c:if>
                <c:if test="${! empty tDictManager.cnNameKey}">
                <c:choose>
                <c:when test="${! empty tDictManager.cnNameName}">
                '${tDictManager.cnNameName}',
                </c:when>
                <c:otherwise>
                '中文名称',
                </c:otherwise>
                </c:choose>
                </c:if>
                <c:if test="${! empty tDictManager.enNameKey}">
                <c:choose>
                <c:when test="${! empty tDictManager.enNameName}">
                '${tDictManager.enNameName}',
                </c:when>
                <c:otherwise>
                '英文名称',
                </c:otherwise>
                </c:choose>
                </c:if>
                <c:if test="${! empty tDictManager.remarkKey}">
                <c:choose>
                <c:when test="${! empty tDictManager.remarkName}">
                '${tDictManager.remarkName}',
                </c:when>
                <c:otherwise>
                '备注',
                </c:otherwise>
                </c:choose>
                </c:if>
            ],
            colModel: [
                {name: 'indx', index: 'indx', hidden: true, key: true},
                <c:if test="${! empty tDictManager.codeKey}">
                {name: 'code', index: 'code', formatter: urlCode},
                </c:if>
                <c:if test="${! empty tDictManager.cnNameKey}">
                {name: 'cnName', index: 'cnName'},
                </c:if>
                <c:if test="${! empty tDictManager.enNameKey}">
                {name: 'enName', index: 'enName'},
                </c:if>
                <c:if test="${! empty tDictManager.remarkKey}">
                {name: 'remark', index: 'remark'}
                </c:if>
            ],
            viewrecords: true,
            autowidth: true,
            height: 'auto',
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            rownumWidth: 35,
            multiselect: true,
            width: $('body').width(),
            pager: "#baseDictPage", //分页工具栏
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                }
                else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $("#baseDict").setGridWidth($(window).width() * 0.98);
                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });
        $("#btnSearch").bind("click", function () {
            reloadGrid();
        });
        $("#btnModify").bind("click", function () {
            var selectedIDs = $("#baseDict").getGridParam("selarrrow");
            if (0 == selectedIDs.length) {
                ShowMessages("对不起,您必须先选择一条记录", "系统提示", "msgwaring", null, 0);
            } else {
                if (1 != selectedIDs.length) {
                    ShowMessages("对不起,您只能选中一条记录", "系统提示", "msgwaring", null, 0);
                } else {
                    location.href = "${basePath}/baseDict/getDictContentDetail?modify=true&tableName=${tDictManager.tableName}&indx=" + selectedIDs[0];
                }
            }
        });
        $("#btnAdd").bind("click", function () {
            location.href = "${basePath}/baseDict/getDictContentDetail?modify=true&tableName=${tDictManager.tableName}&indx=";
        });
        $("#btnDelete").bind("click", function () {
            var selectedIDs = $("#baseDict").getGridParam("selarrrow");
            if (0 == selectedIDs.length) {
                ShowMessages("对不起,您必须先选择一条记录", "系统提示", "msgwaring", null, 0);
            } else {
                showConfirm("确定要删除选中的记录吗?", "系统提示", function () {
                    $.ajax({
                        type: "post",
                        async: false,
                        url: $basePath + "/baseDict/deleteDictContentDetail?tableName=${tDictManager.tableName}",
                        data: {indxs: array2Str(selectedIDs)},
                        success: function (result) {
                            if (result) {
                                showOKMessage('删除成功!', '', function () {
                                    reloadGrid();
                                });
                            } else {
                                ShowMessages("删除失败", "系统提示", "msgwaring", null, 0);
                            }
                        }
                    });
                })
            }
        });
        $("#btnReset").bind("click", function () {
            document.forms[0].reset();
        });

    });
</script>
</body>
</html>
